import config from '@/common/config'
import {
	requestInterceptors,
	responseInterceptors
} from './interceptors.js'
import uviewPlus from 'uview-plus'

// 确保uview-plus已初始化
if (!uni.$u) {
	uni.$u = uviewPlus
}


const initRequest = () => {
	uni.$u.http.setConfig((defaultConfig) => {
		defaultConfig.baseURL = config.baseUrl
		return defaultConfig
	})
	requestInterceptors()
	responseInterceptors()

}

const request = uni.$u.http

export {
	request,
	initRequest
}

export default request